﻿using System;
using System.Windows;
using System.Windows.Documents;
using AnjLab.FX.Sys;

namespace AnjLab.SyncIT.App
{
    /// <summary>
    /// Interaction logic for AboutWindow.xaml
    /// </summary>
    public partial class AboutWindow : Window
    {
        public AboutWindow()
        {
            InitializeComponent();
            _dateTextBlock.Text =
                (AssemblyBuildDateAttribute.GetEntryAssemblyBuildDate() ?? new DateTime(2007, 8, 25)).ToString("d");
            _versionTextBlock.Text = "v" + (TypeReflector.GetEntryAssemblyVersion() ?? new Version(0, 1));
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private static AboutWindow _instance;

        public static void ShowSingle() {
            ClosePrevious();
            _instance = new AboutWindow();
            _instance.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            _instance.ShowDialog();
        }

        public static void ShowSingle(Window owner)
        {
            ClosePrevious();
            _instance = new AboutWindow();
            _instance.Owner = owner;
            _instance.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            _instance.ShowDialog();
        }

        private static void ClosePrevious() {
            if (_instance != null) {
                _instance.Close();
                _instance = null;
            }
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            var link = sender as Hyperlink;
            App.StartBrowser(link.NavigateUri.ToString());
        }
    }
}
